﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Business.Manager;
using Business.IManager;
using System.Data.SqlClient;

namespace OnlinePayment.Admin
{
    public partial class OperatorAuthoritySet : System.Web.UI.Page
    {
        static string roleName;
        IAccountManager accountManager = new AccountManager();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (object.Equals(Request.QueryString["roleName"], null))
                {
                    //RegisterStartupScript("", "<script>alert('自己输入！');</script>");
                }
                else
                {
                    bindRole();         //调用自定义方法显示该管理员当前拥有的权限
                }
                
            }
        }

        private void bindRole()
        {    


            roleName = Request.QueryString["roleName"].ToString();                      //获取管理员登录名
            txtRoleName.Text = roleName;
            List<bool> authoritys=accountManager.getRoleInfor(roleName);                                                      //读取一条记录    
            this.ceckboxSystemSet.Checked = authoritys[0];
            this.ceckboxAnnounManage.Checked = authoritys[1];
            this.ceckboxServiceManage.Checked = authoritys[2];
            this.ceckboxProManage.Checked = authoritys[3];
            this.ceckbocProPost.Checked = authoritys[4];
            this.ceckboxUtilityManage.Checked = authoritys[5];
            this.ceckboxUtilityPost.Checked = authoritys[6];
            this.ceckBoxNetworkManage.Checked = authoritys[7];
            this.ceckboxStuCardManage.Checked = authoritys[8];
            
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            List<bool> authoritys = new List<bool>();
            authoritys.Add(this.ceckboxSystemSet.Checked);
            authoritys.Add(this.ceckboxAnnounManage.Checked);
            authoritys.Add(this.ceckboxServiceManage.Checked);
            authoritys.Add(this.ceckboxProManage.Checked);
            authoritys.Add(this.ceckbocProPost.Checked);
            authoritys.Add(this.ceckboxUtilityManage.Checked);
            authoritys.Add(this.ceckboxUtilityPost.Checked);
            authoritys.Add(this.ceckBoxNetworkManage.Checked);
            authoritys.Add(this.ceckboxStuCardManage.Checked);
            if (accountManager.updateRoleInfor(authoritys, txtRoleName.Text))
            {
                RegisterStartupScript("", "<script>alert('设置成功！');</script>");
            }
            else
            {
                RegisterStartupScript("", "<script>alert('设置失败！')</script>");
            } 
        }
    }
}